﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using BASE;

/// <summary>
/// Summary description for datKhoaNich
/// </summary>
public class datKhoaNick
{
	public datKhoaNick()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    SqlCommand cmd;
    SqlDataReader dr;
    public bool checkKhoaNick(string masv,string trangthai)
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr3"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(constr);
        sqlConnection.Open();
        cmd = new SqlCommand("sp_KhoaNichGetByMaSinhVienAndTrangThai", sqlConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] sqla = new SqlParameter[2];
        sqla[0] = new SqlParameter("masinhvien", DbType.String);
        sqla[1] = new SqlParameter("trangthai", DbType.String);
        sqla[0].Value = masv;
        sqla[1].Value = trangthai;
        cmd.Parameters.AddRange(sqla);

        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            sqlConnection.Close();
            return true;
        }
        sqlConnection.Close();
        return false;

    }
    public void khoaNick(entKhoaNick entKN)
    {
        string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr3"].ConnectionString;
        SqlConnection sqlConnection = new SqlConnection(constr);
        sqlConnection.Open();
        cmd = new SqlCommand("sp_KhoaNichUpdateTrangThai", sqlConnection);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter[] sqla = new SqlParameter[4];
        sqla[0] = new SqlParameter("masinhvien", DbType.String);
        sqla[1] = new SqlParameter("trangthai", DbType.String);
        sqla[2] = new SqlParameter("nguoikhoa", DbType.Int16);
        sqla[3] = new SqlParameter("Lydo", DbType.String);




        sqla[0].Value = entKN.MaSinhVien;
        sqla[1].Value = entKN.TrangThai;
        sqla[2].Value = Utils.getStringSession("userid");
        sqla[3].Value = entKN.LyDo;
        cmd.Parameters.AddRange(sqla);
        cmd.ExecuteNonQuery();     
        sqlConnection.Close();
        
    }
}